package com.learn.ert.config;

import com.learn.ert.interceptor.EmpInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;


@Configuration  //适配器
public class WebMvcConfigurer extends WebMvcConfigurationSupport{



//    @Bean
//    public WebMvcConfigurer getInterfaceAuthCheckInterceptor() {
//        return new WebMvcConfigurer();
//    }
//
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        /** 指定拦截器类 */
//        registry.addInterceptor(new EmpInterceptor())
//                /** 指定该类拦截的url */
//                .addPathPatterns("/**")
//                .excludePathPatterns("/doc.html")
//                .excludePathPatterns("/service-worker.js")
//                .excludePathPatterns("/swagger-resources")
//                .excludePathPatterns("/webjars/**");
//    }


//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        InterceptorRegistration ir = registry.addInterceptor(new EmpInterceptor());
//        // 拦截路径
//        ir.addPathPatterns("/*");
//        // 不拦截路径
//        List<String> irs = new ArrayList<String>();
//        irs.add("/userLogin");
////        irs.add("/api/*");
//        // 开放knife4j
//        irs.add("/doc.html");
//        irs.add("/service-worker.js");
//        irs.add("/swagger-resources");
//        ir.excludePathPatterns(irs);
//    }






//    @Bean
//    public EmpInterceptor getUserInterceptor() {
//        return new EmpInterceptor();
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(getUserInterceptor()).excludePathPatterns("/doc.html")
//                .excludePathPatterns("/service-worker.js")
//                .excludePathPatterns("/swagger-resources")
//                .excludePathPatterns("/webjars/**")
//                .excludePathPatterns("/userLogin");
//        super.addInterceptors(registry);
//    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(new EmpInterceptor());
        registration.addPathPatterns("/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/**/userLogin",            //登录
                "/**/*.html",            //html静态资源
                "/**/*.js",              //js静态资源
                "/**/*.css",             //css静态资源
                "/**/*.woff",
                "/**/*.ttf",
                "/**/doc.html",
                "/**/webjars/**",
                "/**/swagger-resources",
                "/**/service-worker.js",
                "/**/api/eremp/allEmp"
        );
    }
}
